package com.aiju.cash.core.api;

import com.aiju.app.callback.HttpCallback;
import com.aiju.common.http.interceptor.HttpFactory;
import com.aiju.widgit.dialog.DialogHelper;

import java.util.HashMap;
import java.util.Map;

import static com.aiju.app.config.ConfigManager.INIT_SERVER_HOST;

/**
 * @author: 佐为
 * @date: 2017-05-19 09:32
 * @version: V1.0
 * @Description: 会员积分
 */
public class MemberPointApi extends BaseApi {

    private String get = INIT_SERVER_HOST + "/mpoints/get";
    private String update = INIT_SERVER_HOST + "/mpoints/update";
    private String getPointslist = INIT_SERVER_HOST + "/mpoints/getPointslist";
    private String usedPointslist = INIT_SERVER_HOST + "/mpoints/usedPointslist";
    private String getValidPoints = INIT_SERVER_HOST + "/mpoints/getValidPoints";

    private HttpFactory instance;

    public MemberPointApi(DialogHelper dialogHelper) {
        super(dialogHelper);
        instance = HttpFactory.getInstance();
        instance.setDialogHelper(dialogHelper);
    }

    public void setDialogHelper(DialogHelper dialogHelper) {
        instance.setDialogHelper(dialogHelper);
    }

    /**
     * 会员积分获取接口
     *
     * @param callback
     */
    public void get(HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", mUser.getStoreId());
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(get, map, callback);
    }

    /**
     * 会员积分更新接口
     *
     * @param status
     * @param pointsWorth
     * @param useType
     * @param callback
     */
    public void update(String status, String pointsWorth, String useType, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("status", status);
        map.put("pointsWorth", pointsWorth);
        map.put("useType", useType);
        map.put("token", mUser.getToken());
        map.put("storeId", mUser.getStoreId());
        instance.makeProxy().requestPost(update, map, callback);
    }

    /**
     * 优惠折扣列表接口
     *
     * @param memberPhone
     * @param currentNum
     * @param pageSize
     * @param callback
     */
    public void getPointslist(String memberPhone, String currentNum, String pageSize, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("memberPhone", memberPhone);
        map.put("currentNum", currentNum);
        map.put("pageSize", pageSize);
        map.put("token", mUser.getToken());
        map.put("storeId", mUser.getStoreId());
        instance.makeProxy().requestPost(getPointslist, map, callback);
    }

    /**
     * 优惠折扣列表接口
     *
     * @param memberPhone
     * @param currentNum
     * @param pageSize
     * @param callback
     */
    public void usedPointslist(String memberPhone, String currentNum, String pageSize, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("memberPhone", memberPhone);
        map.put("currentNum", currentNum);
        map.put("pageSize", pageSize);
        map.put("token", mUser.getToken());
        map.put("storeId", mUser.getStoreId());
        instance.makeProxy().requestPost(usedPointslist, map, callback);
    }

    /**
     * 优惠折扣列表接口
     *
     * @param memberPhone
     * @param callback
     */
    public void getValidPoints(String memberPhone, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("memberPhone", memberPhone);
        map.put("token", mUser.getToken());
        map.put("storeId", mUser.getStoreId());
        instance.makeProxy().requestPost(getValidPoints, map, callback);
    }
}
